using System.Collections.Generic;
using System.Windows.Forms;
using Belmost4PDA.Constants;
using Belmost4PDA.Fasade;

namespace Belmost4PDA.Logic
{
    public abstract class AbstractControl
    {
        /// <summary>
        /// Creates the specified control type.
        /// </summary>
        /// <param name="controlType">Type of the control.</param>
        /// <returns></returns>
        /// <param name="DataForControl">Data item for control PanelItem or GridItem</param>
        public static AbstractControl Create(string controlType, object DataForControl)
        {
            AbstractControl control = null;
            switch(controlType)
            {
                case ControlType.MainControl:
                    control = new Control_Main();
                    break;
                case ControlType.EditBox:
                    control = new Control_EditBox((PanelItem) DataForControl);
                    break;
                case ControlType.GridGroup:
                    control = new Control_Grid((ParamItem)DataForControl);
                    break;
                case ControlType.GridItem:
                    control = new Control_GridItem((GridItem) DataForControl);
                    break;
                case ControlType.GridIdItem:
                    control = new Control_GridIdItem((GridItem)DataForControl);
                    break;
                case ControlType.Button:
                    control = new Control_Button((PanelItem)DataForControl);
                    break;
                case ControlType.ComboBox:
                    control = new Control_ComboBox((PanelItem)DataForControl);
                    break;
                case ControlType.CheckBox:
                    control = new Control_CheckBox((PanelItem)DataForControl);
                    break;
                case ControlType.RadioGroup:
                    control = new Control_RadioGroup((PanelItem)DataForControl);
                    break;
                case ControlType.Memo:
                    control = new Control_Memo((PanelItem)DataForControl);
                    break;
            }
            return control;
        }

        /// <summary>
        /// Gets the type of the control.
        /// </summary>
        /// <returns></returns>
        public abstract string GetControlType();
        //public abstract List<GridItem> GetGrid();
        public List<AbstractControl> ChildControls = new List<AbstractControl>();

        /// <summary>
        /// Adds the child.
        /// </summary>
        /// <param name="control">The control.</param>
        public void AddChild(AbstractControl control)
        {
            if(!ChildControls.Contains(control))
                ChildControls.Add(control);
        }
        /// <summary>
        /// Gets the grid.
        /// </summary>
        /// <returns></returns>
        public virtual Control_Grid GetGrid()
        {
            return null;
        }

        /// <summary>
        /// Gets the controls of panel.
        /// </summary>
        /// <param name="controlsList">The controls list.</param>
        /// <param name="IdPanel">The id panel.</param>
        public virtual void GetControlsOfPanel(List<AbstractControl> controlsList, int IdPanel)
        {
            // do nothing
        }
        /// <summary>
        /// Gets the mapper.
        /// </summary>
        /// <returns></returns>
        public abstract AbstractMapper GetMapper();

        /// <summary>
        /// Gets the form control.
        /// </summary>
        /// <returns></returns>
        public abstract Control GetFormControl();

        /// <summary>
        /// Gets the caption. "" - means NO CAPTION (for Button for example)
        /// </summary>
        /// <returns></returns>
        public abstract string GetCaption();
    }
}
